<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>my-promise</title>
</head>
<body>
	<script type="text/javascript" src="pr.js"></script>
	<script>
		console.log(MyPromise)
		new MyPromise((resolve, rejecte) => {
			setTimeout(() => {
				resolve(23)
			}, 1000)
		}).then(res=> {
			console.log(res)
		}, reason => {
			console.log(reason)
		})

		// new Promise((resolve, rejecte) => {
		// 	resolve(23)
		// }).then(value => {
		// 	console.log5(value)
		// }, reason =>{
		// 	console.log(reason)
		// })

		// Promise.resolve('1').then(res=> {
		// 	console.log(res)
		// })
		// Promise.reject(2).then(reason => {
		// 	// console.log(reason)
		// },reason => {
		// 	console.log(reason)
		// })
		// 
		// 
		// 
		
		// const p1 = new Promise(resolve => resolve('sp-1'))
		// const p2 = new Promise(resolve => resolve('sp-2'))
		// const p3 = new Promise(resolve => resolve('sp-3'))
		// Promise.all([p1, p2, p3]).then(value => {
		// 	console.log(value) //["sp-1", "sp-2", "sp-3"]
		// }, reason => {
		// 	console.log(reason)
		// })
		// 
		// 
		
		// const p1 = new Promise(resolve => {
		// 	setTimeout(() => {
		// 		resolve('sp-1')
		// 	}, 2000)
		// })
		// const p2 = new Promise((resolve, reject) => {
		// 	setTimeout(() => {
		// 		reject('错误: ep-2')
		// 	}, 3000)
		// })
		// const p3 = new Promise(resolve => {
		// 	setTimeout(() => {
		// 		resolve('sp-3')
		// 	}, 1000)
		// })

		// Promise.race([p1, p2, p3]).then(value => {
		// 	console.log(value) // 约1秒后输出 'sp-3'
		// }, reason => {
		// 	console.log(reason)
		// })


		const p1 = new Promise(resolve => {
			setTimeout(() => {
				resolve('sp-1')
			}, 2000)
		})
		const p2 = new Promise((resolve, reject) => {
			setTimeout(() => {
				reject('错误: ep-2')
			}, 3000)
		})
		const p3 = new Promise((resolve, reject) => {
			setTimeout(() => {
				resolve('错误: ep-3')
			}, 1000)
		})

		Promise.race([p1, p2, p3]).then(value => {
			console.log(value) // 约1秒后输出 '错误: ep-3'
		}, reason => {
			console.log(reason)
		})
		
		
		// const p1 = new Promise(resolve => resolve('sp-1'))
		// const p2 = new Promise((resolve, reject) => reject('ep-2:出错了'))
		// const p3 = new Promise(resolve => resolve('sp-3'))
		// Promise.all([p1, p2, p3]).then(value => {
		// 	console.log(value) 
		// }, reason => {
		// 	console.log(reason) // ep-2:出错了 
		// })

		// new Promise((resolve, reject) => {
		// 	setTimeout(() => {
		// 		reject("失败")
		// 	})
		// })
		// .then(value => {},
		// 	reason => {
		// 		console.log(reason) // 成功
		// 		return `第一个then的返回值`
		// 	}
		// )
		// .then(value => {
		// 	console.log(value) // 第一个then的返回值
		// 	return new Promise(resolve => {
		// 		resolve(123)
		// 	})
		// })
		// .then(value => {
		// 	console.log(value) // 123
		// })


		// const p1 =  new Promise(resolve => resolve(1))
		// const p2 =  new Promise(resolve => resolve(2))
		// 	.then(res => {
		// 		console.log('p2', res)
		// 		return p1
		// 	})
		// 	.then(res => {
		// 		console.log('p1', res)
		// 	})
			/*Chaining cycle detected for promise #<Promise>*/

			
	</script>
</body>
</html>